package xyz.qduwo.servlet.manager;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import xyz.qduwo.dao.UserDao;
import xyz.qduwo.entity.UserEntity;
import xyz.qduwo.util.EncryptUtils;
import xyz.qduwo.util.RespUtils;

/**
 *
 * @author Administrator
 */
@WebServlet("/admin/manager/UpdatePwd")
public class UpdatePassword extends HttpServlet {

    UserEntity user = null;

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        String pwd = req.getParameter("pwd");
        resp.setContentType("application/x-json;charset=utf-8");

        try {
            user = UserDao.getByUserID(id);
            user.setPassword(EncryptUtils.stringToMD5(pwd));
            UserDao.update(user);
            resp.getWriter().println(RespUtils.success());
        }catch(Exception ex){
            resp.getWriter().println(RespUtils.fail("重置密码失败"));
            ex.printStackTrace();
        }
    }

}
